var Toggler = new Class({
	initialize: function(){
		this.prevTrigger = null;
		this.prevIndex = null;
		this.progFx = [];
		//this.close = new Element('span',{'class':'close'})
		this.triggers = $('resultList').getElements('p.info');
		this.triggers.each (function(item, index){
			this.progFx[index] = new Fx.Morph(item.getParent('div').getElement('div.preContainer'),{duration: 300});
			item.addEvent('click', function(){
				this.openDetail(item, index)
			}.bind(this));
		}.bind(this));
	},
	openDetail: function(trigger, index) {
		var close = false;
		if (this.prevIndex != null) {
			if ((trigger == this.prevTrigger) && trigger.hasClass('active')) close = true
			if ((trigger == this.prevTrigger) && !trigger.hasClass('active')) {}
			else this.closeDetail(this.prevTrigger, this.prevIndex)
		}
	
		if (!trigger.hasClass('active') && !close) {
			trigger.addClass('active');
			trigger.getParent('div').getElement('span.expand').set('html','-')
			/* this.close.inject(trigger, 'bottom'); */
			var height = trigger.getParent('div').getElement('pre').getSize().y
			this.progFx[index].start({'height':height})
			this.prevIndex = index;
			this.prevTrigger = trigger;
		}
		close = false;
	},
	closeDetail: function(trigger,index) {
		/* this.close.dispose(); */
		trigger.removeClass('active');
		trigger.getParent('div').getElement('span.expand').set('html','+')
		this.progFx[index].start({'height':0})
	}
});

window.addEvent('load', function(){
	if ($('resultList')) {
		var ToggleDetail = new Toggler();
	}
}.bind(this));
